package com.spark.lola.service.sup.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spark.lola.entity.sup.BankInfo;
import com.spark.lola.entity.sup.SupplierInfo;
import com.spark.lola.mapper.sup.SupplierInfoMapper;
import com.spark.lola.service.sup.ISupplierInfoService;
import com.spark.lola.support.common.constant.CommonConstant;
import com.spark.lola.support.core.vo.SelectMap;
import com.spark.lola.support.mybatis.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dengyejun
 * @since 2020-04-24
 */
@Service
public class SupplierInfoServiceImpl extends BaseServiceImpl<SupplierInfoMapper, SupplierInfo> implements ISupplierInfoService {

    @Override
    public List<SelectMap> selectMap(Long salesmanId,String key) {
        QueryWrapper<SupplierInfo> queryWrapper =new QueryWrapper<>();
        queryWrapper.select("id,name");
        queryWrapper.eq("used", CommonConstant.Y);
        if(salesmanId.intValue() > 0) {
            queryWrapper.eq("salesman_id", salesmanId);
        }
        if(!StringUtils.isEmpty(key)){
           queryWrapper.and(o->o.like("no",key).or().like("name",key));
        }
        List<SupplierInfo> lst = baseMapper.selectList(queryWrapper);
        List<SelectMap> selectMaps =new ArrayList<>();
        if(!CollectionUtils.isEmpty(lst)) {
            lst.forEach(item -> {
                selectMaps.add(new SelectMap(item.getId(), item.getName()));
            });
        }
        return selectMaps;
    }
}
